<?php


namespace App\Api;
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS,PATCH');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

use App\Domain\Order as OrderDomain;
use PhalApi\Api;



class Order extends Api
{
    public function getRules()
    {
        return array(
            'getOrderInfoByUid' => array(
                'user_id' => array('name' => 'user_id', 'require' => true, 'min' => 1, 'desc' => '用户的id')
            ),
            'insertOrderInfo' => array(
                'order_id' => array('name' => 'order_id', 'require' => true, 'min' => 1, 'max' => 150, 'source' => 'post', 'desc' => '订单的id'),
                'order_uaid' => array('name' => 'order_uaid', 'require' => true, 'min' => 1, 'source' => 'post', 'desc' => '订单的地址uaid'),
                'order_uid' => array('name' => 'order_uid', 'require' => true, 'min' => 1,  'source' => 'post', 'desc' => '订单的用户uid'),
                'order_money' => array('name' => 'order_money', 'require' => true, 'min' => 1, 'source' => 'post', 'desc' => '订单的总价'),
            ),
            'deleteOrderInfoByOid' => array(
                'order_id' => array('name' => 'order_id', 'require' => true, 'min' => 1, 'source' => 'post', 'desc' => '商品订单的id'),

            ),
            'updateOrderInfoByOid' => array(
                'order_id' => array('name' => 'order_id', 'require' => true, 'min' => 1,'max' => 150,'source' => 'post', 'desc' => '订单的id'),
            ),
            'likeQueryByOrderId' => array(
                'like_orderId' => array('name' => 'like_orderId', 'require' => true, 'min' => 1, 'desc' => '模糊的订单编号')
            ),
            'getByOrderFlag' => array(
                'orderFlag' => array('name' => 'orderFlag', 'require' => true, 'min' => 1, 'desc' => '订单的状态值')
            ),
            'getByOrderId' => array(
                'orderId' => array('name' => 'orderId', 'require' => true, 'min' => 1,'max' => 150, 'desc' => '订单的id'),

            ),
        );
    }

    /**
     * 返回所有订单列表详细信息
     * @desc 查询所有订单列表信息，返回一组json数据
     */
    public function getOrderList(){
        $domain = new OrderDomain();
        $info = $domain->getOrderList();
        return array('info' => $info);
    }

    /**
     * 返回指定用户id的所有订单信息
     * @desc 查询指定用户的所有订单信息
     * 返回一个json集合
     */
    public function getOrderInfoByUid(){
        $user_id = $_GET['user_id'];
        $domain = new OrderDomain();
        $info = $domain->getOrderInfoByUid($user_id);
        return array('info' => $info);
    }

    /**
     * 创建总订单接口
     * @desc 传入5个参数创建总订单
     * 返回受影响行数
     */
    public function insertOrderInfo(){
        $order_id = $_POST['order_id'];
        $order_uaid = $_POST['order_uaid'];
        $order_uid = $_POST['order_uid'];
        $order_money = $_POST['order_money'];
        $domain = new OrderDomain();
        $row = $domain->insertOrderInfo($order_id, $order_uaid, $order_uid, $order_money);
        return array('row' => $row);
    }

    /**
     * 删除指定id接口
     * @desc 根据订单id删除总订单
     * 返回受影响行数
     */
    public function deleteOrderInfoByOid(){
        $order_id = $_POST['order_id'];
        $domain = new OrderDomain();
        $row = $domain->deleteOrderInfoByOid($order_id);
        return array('row' => $row);
    }

    /**
     * 修改订单为发货状态
     * @desc 根据传回来的订单id，将对应订单修改flag值为2
     */
    public function updateOrderInfoByOid(){
        $order_id = $_POST['order_id'];
        $domain = new OrderDomain();
        $info = $domain->updateOrderInfoByOid($order_id);
        return array('info' => $info);
    }

    /**
     * 按订单编号模糊查询订单信息
     * @desc 传订单编号的相关信息，查询相匹配的用户订单，实现模糊查询
     */
    public function likeQueryByOrderId()
    {
        $like_orderId = $_GET['like_orderId'];
        $domain = new OrderDomain();
        $info = $domain->likeQueryByOrderId($like_orderId);
        return array('info' => $info);
    }

    /**
     * 按订单状态查询订单信息
     * @desc 传订单状态的信息，查询相匹配的用户订单
     */
    public function getByOrderFlag()
    {
        $orderFlag = $_GET['orderFlag'];
        $domain = new OrderDomain();
        $info = $domain->getByOrderFlag($orderFlag);
        return array('info' => $info);
    }
    /**
     * 按订单编号查询订单信息
     * @desc 传订单状态的信息，查询相匹配的用户订单
     */
    public function getByOrderId()
    {
        $orderId = $_GET['orderId'];
        $domain = new OrderDomain();
        $info = $domain->getByOrderId($orderId);
        return array('info' => $info);
    }
}